package com.nomcode.webtextr;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ContactPhoneAdapter extends ArrayAdapter<ContactPhone> {
	
	private List<ContactPhone> contacts;
	public ContactPhoneAdapter(Context context, List<ContactPhone> contacts) {
		super(context, R.layout.list_item_contacts, contacts);
		this.contacts = contacts;
	}
	
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View v = convertView;
		
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_item_contacts, null);
		}
		
		ContactPhone cp = this.contacts.get(position);
		TextView txt = (TextView) v.findViewById(R.id.contactText);
		String rowText = cp.getName() + " <" + cp.getNumber() + "> (" + cp.getType() + ")";
		
		txt.setText(rowText);
		
		return v;
	}
	
	public ContactPhone getContactPhone(int position) {
		ContactPhone cp = this.contacts.get(position);
		return cp;
	}
	
	public void setContactPhoneList(List<ContactPhone> contacts) {
		this.contacts = contacts;
	}
}
